package com.example.hissys.controller;

import com.example.hissys.dto.FeedbackRequest;
import com.example.hissys.entity.Feedback;
import com.example.hissys.service.FeedbackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/feedback")
@CrossOrigin(origins = "*")
@Slf4j
public class FeedbackController {
    @Autowired
    private FeedbackService feedbackService;

    @PostMapping
    public ResponseEntity<?> createFeedback(@Valid @RequestBody FeedbackRequest request) {
        try {
            log.info("Received feedback request: {}", request);
            Feedback feedback = feedbackService.createFeedback(request);
            return ResponseEntity.ok(feedback);
        } catch (Exception e) {
            log.error("Failed to create feedback", e);
            return ResponseEntity.badRequest().body(e.getMessage());
        }
    }
} 